﻿#region File Header
//-----------------------------------------------------------------------------
// SibLib
//
// Copyright (C) 2010 Julien Villers
// This program is distributed under the terms of the 
// GNU Lesser General Public License (LGPL).
// See Docs/lgpl.txt and Docs/gpl.txt
//-----------------------------------------------------------------------------
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SibLib.Text
{
    public class TextArea
    {
        private StringBuilder m_Text;

        public SpriteFont Font
        {
            get;
            set;
        }

        public Color Color
        {
            get;
            set;
        }

        /// <summary>
        /// Top left coordinate of area.
        /// </summary>
        public Vector2 Position
        {
            get;
            set;
        }

        /// <summary>
        /// Size of the area, in pixels.
        /// </summary>
        public Vector2 Size
        {
            get;
            set;
        }

        /// <summary>
        /// Is word wrapping enabled?
        /// </summary>
        public bool IsWordWrapping
        {
            get;
            set;
        }

        public enum E_TextAlign
        {
            Left = 0,
            Right,
            Center,
            Justify
        };

        public E_TextAlign TextAlignment
        {
            get;
            set;
        }

        public TextArea() :
            this(256)
        {
        }

        public TextArea(int maxLength)
        {
            m_Text = new StringBuilder(maxLength);
        }

        public void AddText(string text)
        {
            m_Text.Append(text);
            if (IsWordWrapping)
                WordWrap();
        }

        public void Clear()
        {
            m_Text.Remove(0, m_Text.Length);
        }

        private void WordWrap()
        { 
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();

            if (TextAlignment == E_TextAlign.Left || TextAlignment == E_TextAlign.Justify)
                spriteBatch.DrawString(Font, m_Text, Position, Color);

            spriteBatch.End();
        }
    }
}
